<template>
	<router-view :key="route.path" />
</template>

<script setup>
import { onMounted, nextTick, watch } from 'vue'
import { useRoute } from 'vue-router'
import useSettingsStore from '@/store/modules/settings'
import { handleThemeStyle } from '@/utils/theme'
// import { useRoute } from 'vue-router'

// const route = useRoute()

// const handleVisibilityChange = () => {
// 	console.log('Tab changed')
// 	localStorage.setItem('nowRoutePath', route.path)
// }
// onMounted(() => {
// 	nextTick(() => {
// 		// 初始化主题样式
// 		handleThemeStyle(useSettingsStore().theme)
// 	})
// })
// onBeforeUnmount(() => {
// 	document.removeEventListener('visibilitychange', handleVisibilityChange)
// })


// 刷新数据
const route = useRoute();
const fetchData = () => {
	route.path
}
// 初始加载
onMounted(() => {
	nextTick(() => {
		// 初始化主题样式
		handleThemeStyle(useSettingsStore().theme)
	})
	fetchData();
});
//当路由路径发生变化时重新加载数据
watch(() => route.path, () => {
	fetchData();
});
</script>
